package com.sojson.controller.po;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.sojson.entity.po.UserRole;
import com.sojson.result.Result;
import com.sojson.service.UserRoleService;

/**
 * 用户和角色关联表控制器
 * 
 * @author liu
 * @date 2021-04-15
 */
// @Api(tags = "用户和角色关联表管理")
// @RestController
// @RequestMapping("/userRole")
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;

    /**
     * 单条插入
     * 
     * @param userRole
     * @return
     */
    @PostMapping("/insert")
    public Object insert(@RequestBody UserRole userRole) {
        userRoleService.insert(userRole);
        return Result.success();
    }

    /**
     * 批量插入
     * 
     * @param userRole
     * @return
     */
    @PostMapping("/insertList")
    public Object insertList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.insertList(userRole));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param userRole
     * @return
     */
    @DeleteMapping("/deleteByDto")
    public Object deleteByDto(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.deleteByDto(userRole));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @GetMapping("/countAll")
    public Object countAll() {
        int countAll = userRoleService.countAll();
        return Result.success(countAll);
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @GetMapping("/findAll")
    public Object findAll() {
        List<UserRole> findAll = userRoleService.findAll();
        return Result.success(findAll);
    }

    /**
     * 根据对象统计数量
     * 
     * @param userRole
     * @return
     */
    @GetMapping("/countByDto")
    public Object countByDto(UserRole userRole) {
        int countByDto = userRoleService.countByDto(userRole);
        return Result.success(countByDto);
    }

    /**
     * 根据对象查询
     * 
     * @param userRole
     * @return
     */
    @GetMapping("/findByDto")
    public Object findByDto(UserRole userRole) {
        List<UserRole> findByDto = userRoleService.findByDto(userRole);
        return Result.success(findByDto);
    }

    /**
     * 通过roleId删除(物理删除)
     * 
     * @param roleId
     * @return
     */
    @DeleteMapping("/deleteByRoleId")
    public Object deleteByRoleId(Integer roleId) {
        userRoleService.deleteByRoleId(roleId);
        return Result.success();
    }

    /**
     * 通过roleId列表删除(物理删除)
     * 
     * @param roleIds
     * @return
     */
    @DeleteMapping("/deleteByRoleIdList")
    public Object deleteByRoleIdList(@RequestParam("roleIds") List<Integer> roleIds) {
        return Result.success(userRoleService.deleteByRoleIdList(roleIds));
    }

    /**
     * 通过roleId更新(全部更新)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateByRoleId")
    public Object updateByRoleId(@RequestBody UserRole userRole) {
        userRoleService.updateByRoleId(userRole);
        return Result.success();
    }

    /**
     * 通过roleId列表更新(全部更新)(更新内容相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateStaticByRoleIdList")
    public Object updateStaticByRoleIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateStaticByRoleIdList(userRole));
    }

    /**
     * 通过roleId列表更新(全部更新)(更新内容不相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateChangeByRoleIdList")
    public Object updateChangeByRoleIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateChangeByRoleIdList(userRole));
    }

    /**
     * 通过roleId更新(局部更新)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updatePartialByRoleId")
    public Object updatePartialByRoleId(@RequestBody UserRole userRole) {
        userRoleService.updatePartialByRoleId(userRole);
        return Result.success();
    }

    /**
     * 通过roleId列表更新(局部更新)(更新内容相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateStaticPartialByRoleIdList")
    public Object updateStaticPartialByRoleIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateStaticPartialByRoleIdList(userRole));
    }

    /**
     * 通过roleId列表更新(局部更新)(更新内容不相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateChangePartialByRoleIdList")
    public Object updateChangePartialByRoleIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateChangePartialByRoleIdList(userRole));
    }

    /**
     * 通过roleId查询
     * 
     * @param roleId
     * @return
     */
    @GetMapping("/findByRoleId")
    public Object findByRoleId(Integer roleId) {
        UserRole findByRoleId = userRoleService.findByRoleId(roleId);
        return Result.success(findByRoleId);
    }

    /**
     * 通过roleId列表查询
     * 
     * @param roleIds
     * @return
     */
    @GetMapping("/findByRoleIdList")
    public Object findByRoleIdList(@RequestParam("roleIds[]") List<Integer> roleIds) {
        List<UserRole> findByRoleIdList = userRoleService.findByRoleIdList(roleIds);
        return Result.success(findByRoleIdList);
    }

    /**
     * 通过对象查询roleId列表
     * 
     * @param userRole
     * @return
     */
    @GetMapping("/findRoleIdByDto")
    public Object findRoleIdByDto(UserRole userRole) {
        List<Integer> findRoleIdByDto = userRoleService.findRoleIdByDto(userRole);
        return Result.success(findRoleIdByDto);
    }

    /**
     * 通过userId删除(物理删除)
     * 
     * @param userId
     * @return
     */
    @DeleteMapping("/deleteByUserId")
    public Object deleteByUserId(Integer userId) {
        userRoleService.deleteByUserId(userId);
        return Result.success();
    }

    /**
     * 通过userId列表删除(物理删除)
     * 
     * @param userIds
     * @return
     */
    @DeleteMapping("/deleteByUserIdList")
    public Object deleteByUserIdList(@RequestParam("userIds") List<Integer> userIds) {
        return Result.success(userRoleService.deleteByUserIdList(userIds));
    }

    /**
     * 通过userId更新(全部更新)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateByUserId")
    public Object updateByUserId(@RequestBody UserRole userRole) {
        userRoleService.updateByUserId(userRole);
        return Result.success();
    }

    /**
     * 通过userId列表更新(全部更新)(更新内容相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateStaticByUserIdList")
    public Object updateStaticByUserIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateStaticByUserIdList(userRole));
    }

    /**
     * 通过userId列表更新(全部更新)(更新内容不相同)
     * 
     * @param userRoles
     * @return
     */
    @PutMapping("/updateChangeByUserIdList")
    public Object updateChangeByUserIdList(@RequestBody UserRole userRoles) {
        return Result.success(userRoleService.updateChangeByUserIdList(userRoles));
    }

    /**
     * 通过userId更新(局部更新)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updatePartialByUserId")
    public Object updatePartialByUserId(@RequestBody UserRole userRole) {
        userRoleService.updatePartialByUserId(userRole);
        return Result.success();
    }

    /**
     * 通过userId列表更新(局部更新)(更新内容相同)
     * 
     * @param userRole
     * @return
     */
    @PutMapping("/updateStaticPartialByUserIdList")
    public Object updateStaticPartialByUserIdList(@RequestBody UserRole userRole) {
        return Result.success(userRoleService.updateStaticPartialByUserIdList(userRole));
    }

    /**
     * 通过userId列表更新(局部更新)(更新内容不相同)
     * 
     * @param userRoles
     * @return
     */
    @PutMapping("/updateChangePartialByUserIdList")
    public Object updateChangePartialByUserIdList(@RequestBody UserRole userRoles) {
        return Result.success(userRoleService.updateChangePartialByUserIdList(userRoles));
    }

    /**
     * 通过userId查询
     * 
     * @param userId
     * @return
     */
    @GetMapping("/findByUserId")
    public Object findByUserId(Integer userId) {
        UserRole findByUserId = userRoleService.findByUserId(userId);
        return Result.success(findByUserId);
    }

    /**
     * 通过userId列表查询
     * 
     * @param userIds
     * @return
     */
    @GetMapping("/findByUserIdList")
    public Object findByUserIdList(@RequestParam("userIds[]") List<Integer> userIds) {
        List<UserRole> findByUserIdList = userRoleService.findByUserIdList(userIds);
        return Result.success(findByUserIdList);
    }

    /**
     * 通过对象查询userId列表
     * 
     * @param userRole
     * @return
     */
    @GetMapping("/findUserIdByDto")
    public Object findUserIdByDto(UserRole userRole) {
        List<Integer> findUserIdByDto = userRoleService.findUserIdByDto(userRole);
        return Result.success(findUserIdByDto);
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    @DeleteMapping("/clear")
    public Object clear() {
        userRoleService.clear();
        return Result.success();
    }

}